package com.ccys.cms.controller.discount;

import cn.hutool.core.util.ObjectUtil;
import com.ccys.cms.service.discount.PromoCodeService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.discount.PromoCodeDto;
import com.ccys.db.dto.discount.PromoCodeMemberDto;
import com.ccys.db.entity.TblPlan;
import com.ccys.db.vo.discount.PromoCodeFindListSelectVo;
import com.ccys.db.vo.discount.PromoCodeMemberFindByCodeIdVo;
import com.ccys.db.vo.discount.PromoCodePageQueryVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @program: WhiteCoat
 * @description: 优惠卷接口
 * @author: ZhangJingCan
 * @create: 2023-12-15 13:45
 **/

@RestController
@RequestMapping("discount")
@Api(tags = "discount-优惠卷接口")
public class PromoCodeController {

    @Autowired
    private PromoCodeService promoCodeService;


    //todo: GoApotik voucher 第三方接口获取 - 目前获取不了
    @PostMapping("promoCode")
    @ApiOperation("保存优惠卷")
    public ResponseResult savePromoCode(PromoCodeDto dto) {
        return promoCodeService.savePromoCode(dto);
    }

    @DeleteMapping("promoCode")
    @ApiOperation("根据ID删除优惠卷")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult deletePromoCode(@ApiIgnore PromoCodeDto dto) {
        return promoCodeService.deletePromoCode(dto);
    }

    @GetMapping("promoCode")
    @ApiOperation("分页查询优惠卷")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "name模糊查询/页面上展示为Code", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "country", value = "country/查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "specialisationIds", value = "0:GP;1:Peadiatrics;2:OAG;3:Psychology;/这个是模糊查询的，选择某一个，模糊查询，查询所有就传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "0:free delivery(快递费用免费);1:fixed $ off bill(账单抵扣金额);2:% off bill(账单打折);" +
                    "3:fixed $ off consultation(问诊费用抵扣金额);4:% off consultation(问诊费用打折);5:fixed $ off delivery(快递费用抵扣金额);" +
                    "6:% off delivery(快递费用打折);7:%off consultation + % off delivery(问诊费用与快递费用同时打折)/查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "0/1,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "orderByStr",
                    value = "(默认传：t1.created_on descend),(左到右依次:t1.code,t1.discount_label,t1.type,t1.amount,t1.limit_number,t1.start_date,t1.end_date,t1.reusable,t1.status,t2.user_fullname,t1.created_on)",
                    required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<PageInfo<PromoCodePageQueryVo>, Object> findPagePromoCode(@ApiIgnore PromoCodeDto dto) {
        return promoCodeService.findPagePromoCode(dto);
    }

    @PutMapping("promoCode/status")
    @ApiOperation("根据ID修改优惠卷状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态：0-禁用，1-启用", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updatePromoCodeStatus(@ApiIgnore PromoCodeDto dto) {
        return promoCodeService.updatePromoCodeStatus(dto);
    }

    @GetMapping("findPlanByType")
    @ApiOperation("根据Type查询配套")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1:AIA corporate;2:Direct corporate;3:AIA Healthshield;4:Subscription", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<List<TblPlan>, Object> findPlanByType(Integer type) {
        if (ObjectUtil.isEmpty(type)) {
            return ResponseResult.error("Parameter Error!");
        }
        return promoCodeService.findPlanByType(type);
    }

    @GetMapping("findPromoCodeByCode")
    @ApiOperation("根据传入的code查询是否存在")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "根据传入的code查询是否存在，存在则返回error，不存在返回success", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult findPromoCodeByCode(String code) {
        if (ObjectUtil.isEmpty(code)) {
            return ResponseResult.error("Parameter Error!");
        }
        return promoCodeService.findPromoCodeByCode(code);
    }

    @PostMapping("promoCode/promoCodeMember")
    @ApiOperation("添加优惠卷用户限制名单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "promoCodeId", value = "当前优惠卷ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "memberId", value = "当前选中用户ID", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "allowChild", value = "是否允许这个用户的孩子使用，0-不允许，1-允许", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult addPromoCodeMember(@ApiIgnore PromoCodeMemberDto dto) {
        return promoCodeService.addPromoCodeMember(dto);
    }

    @DeleteMapping("promoCode/promoCodeMember")
    @ApiOperation("删除优惠卷限制用户-根据数据ID")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult deletePromoCodeMember(@ApiIgnore PromoCodeMemberDto dto) {
        return promoCodeService.deletePromoCodeMember(dto);
    }

    @GetMapping("promoCode/promoCodeMember")
    @ApiOperation("查询优惠卷限制用户列表-根据当前优惠卷ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<PageInfo<PromoCodeMemberFindByCodeIdVo>, Object> findPromoCodeMember(@ApiIgnore PromoCodeDto dto) {
        return promoCodeService.findPromoCodeMember(dto);
    }

    @GetMapping("promoCode/findListSelect")
    @ApiOperation("优惠卷的下拉列表")
    public ResponseResult<List<PromoCodeFindListSelectVo>, Object> findListSelect() {
        return promoCodeService.findListSelect();
    }

}
